use std::fmt::Write;

use bytestring::ByteString;
use datafusion::arrow::datatypes::{DataType, TimeUnit};

#[derive(Debug, PartialEq)]
pub enum FieldValue {
    I64(i64),
    F64(f64),
    Timestamp(u64),
    String(ByteString),
}

impl FieldValue {
    pub fn print(&self, builder: &mut String) {
        match self {
            FieldValue::I64(v) => {
                write!(builder, "{}", v).unwrap();
            }
            FieldValue::F64(v) => {
                write!(builder, "{}", v).unwrap();
            }
            FieldValue::Timestamp(v) => {
                write!(builder, "{}", v).unwrap();
            }
            FieldValue::String(v) => {
                write!(builder, "\"{}\"", v).unwrap();
            }
        }
    }

    #[inline]
    pub fn data_type(&self) -> DataType {
        match self {
            FieldValue::I64(_) => DataType::Int64,
            FieldValue::F64(_) => DataType::Float64,
            FieldValue::Timestamp(_) => DataType::Timestamp(TimeUnit::Millisecond, None),
            FieldValue::String(_) => DataType::Utf8,
        }
    }
}